//
// Created by v on 19-4-22.
//

#include "CMCommandInstance.h"

CMCommandInstance::CMCommandInstance(std::string name, std::string description)
{
    m_name        = name;
    m_description = description;
}

CMCommandInstance::~CMCommandInstance() {}

std::string CMCommandInstance::getShellPath()
{
    return std::string(m_name + "_dir");
}

void CMCommandInstance::showUsage()
{
    printf("%15s : %s", m_name.c_str(), m_description.c_str());
}

int CMCommandInstance::startTest(int argc, char **args)
{
    for (int i = 0; i < argc; i++)
    {
        m_args.push_back(args[i]);
    }

    std::string path      = getShellPath();
    std::string shellname = "./" + path + "/start.sh";
    LOGD("Auto test execute shell name start %s\n", shellname.c_str());
    system(shellname.c_str());

    int ret   = testCommand();
    shellname = "./" + path + "/end.sh";
    LOGD("Auto test execute shell name end %s\n", shellname.c_str());
    system(shellname.c_str());

    return ret;
}
